﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;

namespace TransactionServer.OSActivities77
{
    using TransactionServer.General_Classes;

    public sealed class OSCreate77 : CodeActivity
    {
        // Define an activity input argument of type string
        public InArgument<Context> Context { get; set; }
        public InOutArgument<Entity> Entity { get; set; }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            Entity Entity = context.GetValue(this.Entity);
            Context con = context.GetValue(this.Context);
            OSConnector77 conn = (OSConnector77)con.Connector[Entity.System];

            object osEntity = conn.ConvertFrom(Entity);
            String id = conn.SaveEntity(osEntity);

            if (Entity.Name.Contains("ТабличнаяЧасть."))
            {
                id = id + "/" + conn.getRowCount(osEntity, Entity.Name.Split('.')[1]);
            }
            Entity.Id = id;

            context.SetValue(this.Entity, Entity);
        }
    }
}
